
var api = require('../../../utils/api.js')
var $ = require('../../../utils/util.js')
var regeneratorRuntime = require('../../../utils/runtime.js')
var app = getApp()


Page({
  data: {

    hasMore: true,// 判断 数据是否全部加载完 
    isLodingLock: true, //锁 防止数据加载
    pageList: [], //分页数据列表
    pageNum: 1, //页码
    isShowKong: false, // 是否是空
    keyword: '', // 搜索关键字

    currentTab: 0, // 当前选中的tab
    nav: [
      { name: '未处理', type: 1, num: 0, color: '#dd524d', icon: 'icon-shijian' },
      { name: '已处理', type: 2, num: 0, color: '#16304f', icon: 'icon-tick' }
    ], // tab 
  },

  onLoad: function (options) {
   // this.count();
   // this.getPagServer(1, true) //获取分页数据
  },
  onShow: function () {
    this.count();
    this.onPullDownRefresh();
  },
  count(){
    app._total({ type: 5, is_all: 1 }).then((res) => {
      var nav = this.data.nav
      nav[0].num = res.data.un_deal
      nav[1].num = res.data.to_deal
      this.setData({ nav })
    })
  },
  onReachBottom() { //滑动到底部触发
    this.loadingMore()
  },
  onPullDownRefresh: function () { // 下拉刷新
    this.getPagServer(1, true) //获取分页数据
  },


  loadingMore: function () {  // 加载更多 
    if (this.data.isLodingLock) {
      this.setData({
        isLodingLock: false
      })

      this.getPagServer()
    }
  },


  getPagServer(pageNum, isClickTab = false) { //分页  
    var params = {
      pageNum: pageNum == 1 ? 1 : this.data.pageNum,
      pageSize: 10,
      type: this.data.nav[this.data.currentTab].type,
      keyword: this.data.keyword
    }
    $.getPageList(api, this, api.defect.getList1, params, isClickTab).then((res) => {
      wx.stopPullDownRefresh() // 接口数据请求完停止刷新
    })
  },

  //##input 输入##
  input_handle(e) {
    this.setData({
      [e.currentTarget.dataset.key]: e.detail.value
    })
  },
  //##input 输入##

  keywordConfirmHandle() { // 搜索输入框 
    if ($.isNull(this.data.keyword)) {
      $.toast('请输入内容')
    } else {
      this.getPagServer(1, true) //获取分页数据
    }

  },

  tabHanlde(e) {
    var { index } = e.detail
    this.setData({
      currentTab: index
    })
    this.getPagServer(1, true) //获取分页数据
  },

  toDefectManageFlawRegister(e) { // 去未处理的详情 
    var { item } = $.detail(e)
    $.linkurl(`/pages/defectManage/defectManageFlawRegister/defectManageFlawRegister?info=${JSON.stringify(item)}&type=2&isUpdata=1`)
  },
  toDefectManageDetails(e){ // 去缺陷详情
    var { item } = $.detail(e)
    $.linkurl(`/pages/defectManage/defectManageDetails/defectManageDetails?id=${item.id}&number=${item.number}`)
  },
  toDefectManageFlawRegisterHandle(){ // 去添加缺陷
    $.linkurl(`/pages/defectManage/defectManageFlawRegister/defectManageFlawRegister?type=2`)
  }

})